<style scoped lang="less">
  .record-container {
    background-color: white;
    padding: 2vh 3vw;
  }

  .record-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: @--gray 1px solid;
    padding: 2vw;
  }

  .record-money {
    font-size: 0.6rem;
    color: @--price;
  }

  .record-status {
    font-size: 0.4rem;
    color: @--primary;
  }

  .record-date, .record-no {
    font-size: 0.4rem;
    color: @--gray;
  }
</style>
<template>
  <div class="record-container" v-if="list!==null">
    <div class="item-wrap">
      <van-list
        v-model="loading"
        :finished="finished"
        :finished-text="'没有更多了'"
        @load="onLoad"
      >
        <div v-for="(item,index) in list" :key="index">
          <div class="record-item">
            <div class="record-money">{{item.money/100}}</div>
            <div>
              <div class="record-date">{{item.create_time.substr(0,16)}}</div>
              <div class="record-no">NO:{{item.id}}</div>
            </div>
            <div class="record-status">{{getStatusStr(item.status)}}</div>
          </div>
        </div>
      </van-list>
    </div>
  </div>
</template>
<script>
  import {getRecord} from "@/api/withdrawals";
  import Vue from 'vue';
  import {List} from 'vant';

  Vue.use(List);

  //0待提现 5已提现 10关闭
  const STATUS_UN_OP = 0;
  const STATUS_FINISH = 5;
  const STATUS_CLOSE = 10;

  export default {
    name: 'withdrawals-record',
    data() {
      return {
        loading: false,
        finished: false,
        list: [],
        count: 0,
        size: 10
      };
    },
    methods: {
      onLoad() {
        this.getList();
      },
      getStatusStr(status) {
        let str = '';
        if (status === STATUS_CLOSE) {
          str = '已关闭';
        } else if (status === STATUS_UN_OP) {
          str = '待处理';
        } else if (status === STATUS_FINISH) {
          str = '已完成';
        }
        return str;
      },
      getList() {
        if (this.finished) {
          return;
        }
        let page = this.list.length / this.size + 1;
        getRecord({goods_id: this.goods_id, size: this.size, page: page}).then(rep => {
          this.count = rep.data.data.count;
          this.list = this.list.concat(rep.data.data.list);
          if (this.list.length === rep.data.data.count) {
            this.finished = true;
          }
        })
      }
    }
  }
</script>